<template>
	<view class="login">
		
	
		<swiper vertical="true" style="height: 100vh;"> 
			<swiper-item>
				<scroll-view>
			<view class="login-tel">
				 <view class="login-main">
				 	<view class="close">
						<image class="close-img" src="../../static/image/close.png" mode="" @tap="goBack"></image>
					</view>
					<view class="logo">
						<image class="login-logo" src="../../static/img/logo_6.jpg" mode=""></image>
					</view>
					<view class="logo-text" @tap="goToLonginTel">
						手机号注册
					</view>
					<login></login>
					<view class="login-go">
						<view>
							已有账号,去登录
						</view>
						<image src="../../static/image/down.png" mode=""></image>
					</view>
				 </view>
			</view>
				</scroll-view>
			</swiper-item>
			<swiper-item>
				<scroll-view>
					
					<view class="login-tel">
						 <view class="login-main">
						 	<view class="close close-content up">
								<view><image class="close-img" src="../../static/image/close.png" mode="" @tap="goBack"></image></view>
								<view class="login-up">
										<image class="close-img" src="../../static/image/up.png" mode=""></image>
										<view class="">
											没有账号，去注册
										</view>			
								</view>
								<view></view>
								</view>
								<view class="login-form">
									<view class="user">
										<text class="user-text">账号:</text>
										<input type="text" v-model="userName" placeholder="请输入手机号/昵称">
									</view>
									<view class="user">
										<text class="user-text">密码:</text>
										<input type="password" v-model="userPwd" placeholder="6-16位字符">
									</view>
								</view>
								<view class="login-quick">
									<view>忘记密码</view>
									<view>免密登录</view>
								</view>
								<view class="logo-text" @tap="submit">
									登录
								</view>
								<view class="reminder">
									温馨提示:您可以选择免密登录更加方便
								</view>
								<login></login>
							</view>
					</view>
				</scroll-view>
			</swiper-item>
		</swiper>
		
	
		

		
		
		
	</view>
</template>

<script>
	import {mapMutations} from "vuex"
	import $http from "@/common/api/request.js"
	import login from "@/component/login.vue"
	export default {
		data() {
			return {
				userName:'',
				userPwd:'',
				rules:{
					userName:{
						rule:/\S/,
						msg:"账号不能为空"
					},
					userPwd:{
						role:/^[0-9a-zA-Z_#]{6,16}$/,
						msg:"密码应该为6-16位字符"
					}
				},
	
			}
		},
		methods: {
			...mapMutations(['login']),
			goBack(){
				uni.navigateBack({
					delta:1
				})
			},
			submit(){
				if( !this.validate('userName') ) return;
		        if( !this.rules.userPwd.role.test(this.userPwd)){
					uni.showToast({
						title:this.rules['userPwd'].msg,
						icon:'none'
					})
				return;
				}
				uni.showLoading({
					title:"登录中"
				})
				
				$http.request({
					url: "/login",
					method:"POST",
					data:{
						userName:this.userName,
						userPwd:this.userPwd
					},
					
				}).then((res) => {
					if(res.data){
						uni.showToast({
							title:res.msg,
							icon:"success"
						})
					}else{
						uni.showToast({
							title:res.msg,
							icon:"error"
						})
					}
					this.login(res.data)
					setTimeout(()=>{
						uni.hideLoading();
						uni.navigateBack({
							delta:1
						})
					},2000)
				}).catch(() => {
				})
	
			},
			validate(key){
				let bool=true;
				if( !this.rules[key].rule.test(this[key]) ){
					uni.showToast({
						title:this.rules[key].msg,
						icon:'none'
					})
					bool=false;
					return false; 
				}
				return bool; 
			},
			goToLonginTel(){
				uni.navigateTo({
					url:"/pages/login-tel/login-tel"
				})
			}
		},
		components:{
			login
		}
	}
</script>
<style scoped>
	.logo-tel{
		width: 100vw;
		width: 100vh;
		line-height: 80rpx;
	}
	.logo-main{
		padding: 0 20rpx;
	}
	.close{
		padding: 80rpx 0;
	}
	.close-img{
		height: 60rpx;
		width: 60rpx;
	}
	.login-logo{
		padding-bottom: 50rpx;
		padding-top: 30rpx;
		padding-left: 22%;
		display: flex;
		justify-content: center;
		width: 400rpx;
		height: 400rpx;
	}
	.logo-text{
		margin-bottom: 50rpx;
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		color: white;
		background-color: #42B7FB;
		border-radius: 40rpx;
	}
	.login-go{
		color: #acacac;
		padding-top: 150rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}
	.login-go image{
		width: 60rpx;
		height: 60rpx;
	}
	/* 二 */
	.close-content{
		display: flex;
	}
	.close-content>view{
		flex: 1;
	}
	.login-form{
		padding-top:100rpx;
	}
	.user{
		font-size: 32rpx;
		padding: 10rpx 0;
		display: flex;
		align-items: center;
		border-bottom: 2rpx solid  #acacac;
	}
	.user-text{
		padding-right: 10rpx;
	}
	.login-quick{
		display: flex;
		justify-content: space-between;
		padding: 20rpx 0;
	}
	.reminder{
		color: #acacac;
		padding: 10rpx 0;
		text-align: center;
	}
	.login-up{
	    color: #acacac;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}
</style>
